<template>
  <div>
    <el-container>
      <el-header>
        <div>
          <img src="../../public/Snipaste_2023-02-13_14-48-47.png" alt="" />
          <span>电商后台管理系统</span>
        </div>
        <div>
          <button @click="exit">退出</button>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '200px' : '45px'">
          <i class="el-icon-s-operation" @click="isCollapse = !isCollapse"></i>

          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
          >
            <el-submenu
              :index="item.path"
              v-for="(item, index) in list"
              :key="item.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item :index="ele.path" v-for="ele in item.children">{{
                  ele.authName
                }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { menus } from "../utils/api";
export default {
  data() {
    return {
      list: [],
      isCollapse: true,
    };
  },
  methods: {
    // 退出
    exit() {
      localStorage.removeItem("token");
      this.$router.push("/login");
    },
  },
  created() {
    menus().then((res) => {
      console.log(res);
      this.list = res.data.data;
    });
  },
  mounted() {},
  components: {},
  computed: {},
  watch: {},
};
</script>

<style lang="scss" scoped>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  height: 100vh;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  // text-align: center;
  // line-height: 160px;
}
.el-header {
  display: flex;
  justify-content: space-between;
  div {
    display: flex;
    justify-content: space-between;
    img {
      width: 80px;
      height: 60px;
      border-radius: 30px;
    }
    span {
      font-size: 23px;
      color: #fff;
    }
  }
}
</style>
